﻿Public Class TinhThueThuNhapCaNhan

    Dim tienthunhap As Integer = 0

    Private Sub TinhThueThuNhapCaNhan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbNguoi.DataSource = ProcFunc.ExecuteFuncSQL("select * from [User]")
        cbNguoi.ValueMember = "MaUser"
        cbNguoi.DisplayMember = "TenUser"

        cbMucThue.SelectedIndex = 0
        rdbThang.Checked = True
    End Sub

    Private Sub btnTinh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTinh.Click
        lblThanhTien.Text = ""
        Dim str As String = "select isnull(sum(SoTien),0) from PhieuThu where MaUser = '" & cbNguoi.SelectedValue & "'"
        If rdbThang.Checked Then
            str = str & " and month(ngay) = " & cbThang.Text & " and year(ngay) = " & cbNam.Text
        Else
            str = str & " and year(ngay) = " & cbNam.Text
        End If

        tienthunhap = ProcFunc.ExecuteFuncSSQL(str)
        Dim tienthue As Integer = Math.Round((tienthunhap * Convert.ToDouble(cbMucThue.Text) / 100), 0).ToString
        If tienthue > 999 Then
            Dim t As Integer = 0
            Dim arr As New ArrayList
            While tienthue.ToString.Length > 3
                arr.Add(tienthue.ToString.Substring(tienthue.ToString.Length - 3, 3))
                tienthue = Int(tienthue / 1000)
                t = t + 1
            End While
            arr.Add(tienthue.ToString)
            t = arr.Count
            While t > 0
                lblThanhTien.Text = lblThanhTien.Text & arr.Item(t - 1).ToString() & ","
                t = t - 1
            End While
            lblThanhTien.Text = lblThanhTien.Text.Substring(0, lblThanhTien.Text.Length - 1)
        Else
            lblThanhTien.Text = tienthue.ToString
        End If

    End Sub

    Private Sub rdbThang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbThang.CheckedChanged
        If rdbThang.Checked = True Then
            cbThang.Enabled = True
            cbNam.Enabled = True
        Else
            cbThang.Enabled = False
            cbNam.Enabled = False
        End If
    End Sub
End Class